//
//  HMSportTrackingLine.m
//  XRSport
//
//  Created by acer on 16/10/23.
//  Copyright © 2016年 apple. All rights reserved.
//

#import "HMSportTrackingLine.h"

@implementation HMSportTrackingLine
- (instancetype)initWithStartP:(CLLocation *)startP endP:(CLLocation *)endP
{
    if (self = [super init]) {
        _startLocation = startP;
        _endLocation = endP;
    }
    return self;
}

-(HMSportPolyline *)polyline
{
    CLLocationCoordinate2D coord[2];//存放两个点的坐标
    coord[0] = _startLocation.coordinate;
    coord[1] = _endLocation.coordinate;
    
    //speed 0 - 0, speed 20 - 1
//    NSLog(@"%lf,%lf,%lf",self.speed,self.time,self.distance);
    double red = self.speed * 10 / 255.0;
    if (red > 1) {
        red = 1;
    }
    UIColor *color = [UIColor colorWithRed:red green:1 blue:0 alpha:1];
    
    return [HMSportPolyline polylineWithCoordinates:coord count:2 color:color];
}

-(double)speed
{
    return (_startLocation.speed + _endLocation.speed) * 0.5 * 3.6;
}
-(NSTimeInterval)time
{
    return [_endLocation.timestamp timeIntervalSinceDate:_startLocation.timestamp];
}
-(double)distance
{
    return [_endLocation distanceFromLocation:_startLocation] * 0.001;
}
@end
